﻿<%@ Page Language="C#" MasterPageFile="~/PageDefault.Master" AutoEventWireup="true"
    CodeBehind="BeneficiarioWF.aspx.cs" Inherits="SPM.WebForm1" Title="Manutenção de Beneficiario" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <center><h4>Manutenção de Beneficiários</h4></center>
    <asp:GridView ID="GridView1" 
                  runat="server" 
                  AllowPaging="True" 
                  DataKeyNames="idBeneficiario"
                  AllowSorting="True" 
                  AutoGenerateColumns="False" 
                  DataSourceID="SqlDataSource1"
                  EmptyDataText="Nenhum beneficiário encontrado." 
                  OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                  HorizontalAlign="Center" 
                  PageSize="5" BackColor="White" BorderColor="#E7E7FF" 
        BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <Columns>
            <asp:BoundField DataField="nome" HeaderText="Nomes" SortExpression="nome"/>
            <asp:BoundField DataField="dataNascimento" HeaderText="Nascimento" SortExpression="dataNascimento" />
            <asp:BoundField DataField="endereco" HeaderText="Endereço" SortExpression="endereco" />
            <asp:CommandField ShowSelectButton="True" SelectText="Exibir" ShowDeleteButton="True"  />
        </Columns>
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        <HeaderStyle BackColor="Gray" Font-Bold="True" ForeColor="Black" 
            Font-Size="Medium" />
        <AlternatingRowStyle BackColor="#F7F7F7" />
    </asp:GridView>
    <br />
    <br />
    <asp:FormView ID="FormView1" 
                  runat="server"
                  DataSourceID="SqlDataSource1"
                  DataKeyNames="idBeneficiario"
                  EmptyDataText="Nenhum beneficiário selecionado."
                  Height="72px" HorizontalAlign="Center"
                  DefaultMode="Insert" BackColor="White" BorderColor="#E7E7FF" 
                  BorderStyle="None" BorderWidth="1px" CellPadding="3" 
        GridLines="Horizontal" onpageindexchanging="FormView1_PageIndexChanging">
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
        <EditItemTemplate>
            <table cellpadding="0" cellspacing="0">
                <tr>
                   <td align="left">ID:</td>
                   <td><asp:Label ID="idBeneficiarioLabel1" runat="server" Text='<%# Eval("idBeneficiario") %>' /></td>    
                </tr>
                <tr>
                    <td align="left">Nome:</td>
                   <td><asp:TextBox ID="nomeTextBox" runat="server" Text='<%# Bind("nome") %>' /></td>
                </tr>
                <tr>
                    <td align="left">Idade:</td>
                    <td><asp:TextBox ID="idadeTextBox" runat="server" Text='<%# Bind("idade") %>' /></td>
                </tr>   
                <tr>
                    <td align="left">Responsável:</td>
                    <td><asp:TextBox ID="responsavelTextBox" runat="server" Text='<%# Bind("responsavel") %>' /></td>
                </tr>
                <tr>
                    <td align="left">Endereço:</td>
                    <td><asp:TextBox ID="enderecoTextBox" runat="server" Text='<%# Bind("endereco") %>' /></td>
                </tr>
                <tr>
                    <td align="left">Nascimento:</td>
                    <td><asp:TextBox ID="dataNascimentoTextBox" runat="server" Text='<%# Bind("dataNascimento") %>' />
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Data Inválida"
                                        ValidationExpression="^(\d{1,2})/(\d{1,2})/(\d{4})$" 
                                        ControlToValidate="dataNascimentoTextBox"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td align="left">Bairro:</td>
                    <td><asp:TextBox ID="bairroTextBox" runat="server" Text='<%# Bind("bairro") %>' /></td>
                </tr>
                <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                <tr>
                    <td colspan="2">
                        <center>
                            <asp:LinkButton ID="UpdateButton" 
                                            runat="server" 
                                            CausesValidation="True" 
                                            CommandName="Update"
                                            Text="Atualizar" />
                            &nbsp;&nbsp;&nbsp;
                            <asp:LinkButton ID="UpdateCancelButton" 
                                            runat="server" 
                                            CausesValidation="False"
                                            CommandName="Cancel" Text="Cancelar" />
                        </center>
                    </td>
                </tr>
            </table>
        </EditItemTemplate>
        <InsertItemTemplate>
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td>Nome:</td>
                    <td><asp:TextBox ID="nomeTextBox" runat="server" Text='<%# Bind("nome") %>' MaxLength="40" /></td>
                </tr>
                <tr>
                    <td>Idade:</td>
                    <td><asp:TextBox ID="idadeTextBox" runat="server" Text='<%# Bind("idade") %>' /></td>
                </tr>
                <tr>
                    <td>Responsável:</td>        
                    <td><asp:TextBox ID="responsavelTextBox" runat="server" Text='<%# Bind("responsavel") %>' /></td>
                </tr>
                <tr>
                    <td>Endereço:</td>
                    <td><asp:TextBox ID="enderecoTextBox" runat="server" Text='<%# Bind("endereco") %>' /></td>
                </tr>
                <tr>
                    <td>Nascimento:</td>
                    <td><asp:TextBox ID="dataNascimentoTextBox" runat="server" Text='<%# Bind("dataNascimento") %>' /></td>
                </tr>
                <tr>
                    <td>Bairro:</td>
                    <td><asp:TextBox ID="bairroTextBox" runat="server" Text='<%# Bind("bairro") %>' /></td>
                </tr>
                <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
                <tr>
                    <td colspan="2">
                        <center>
                             <asp:LinkButton ID="InsertButton" 
                                            runat="server" 
                                            CausesValidation="True" 
                                            CommandName="Insert"
                                            Text="Inserir" />
                             &nbsp;
                            <asp:LinkButton ID="InsertCancelButton" 
                                            runat="server" 
                                            CausesValidation="False"
                                            CommandName="Cancel" Text="Cancelar" />
                            </center>
                    </td>
                </tr>
            </table>
        </InsertItemTemplate>
        <ItemTemplate>
            ID:
            <asp:Label ID="idBeneficiarioLabel" runat="server" Text='<%# Eval("idBeneficiario") %>' />
            <br />
            Nome:
            <asp:Label ID="nomeLabel" runat="server" Text='<%# Bind("nome") %>' />
            <br />
            Idade:
            <asp:Label ID="idadeLabel" runat="server" Text='<%# Bind("idade") %>' />
            <br />
            Responsável:
            <asp:Label ID="responsavelLabel" runat="server" Text='<%# Bind("responsavel") %>' />
            <br />
            Endereço:
            <asp:Label ID="enderecoLabel" runat="server" Text='<%# Bind("endereco") %>' />
            <br />
            Nascimento:
            <asp:Label ID="dataNascimentoLabel" runat="server" Text='<%# Bind("dataNascimento") %>' />
            <br />
            Bairro:
            <asp:Label ID="bairroLabel" runat="server" Text='<%# Bind("bairro") %>' />
            <br />
            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                Text="Editar" />
            &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
                Text="Excluir" />
            &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
                Text="Novo" />
        </ItemTemplate>
        <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SPM %>"
        SelectCommand="SELECT [idBeneficiario], [nome], [idade], [responsavel], [endereco], [dataNascimento], [bairro] FROM [beneficiario] ORDER BY [nome]"
        InsertCommand="INSERT INTO beneficiario VALUES (@nome, @dataNascimento, @idade, @responsavel, @endereco, @bairro)"
        UpdateCommand="UPDATE beneficiario SET nome = @nome, dataNascimento = @dataNascimento, idade = @idade, responsavel = @responsavel, endereco = @endereco, bairro = @bairro WHERE (idBeneficiario = @idBeneficiario)"
        DeleteCommand="DELETE FROM beneficiario WHERE (idBeneficiario = @idBeneficiario)">
        <DeleteParameters>
            <asp:Parameter Name="idBeneficiario" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="nome" />
            <asp:Parameter Name="dataNascimento" />
            <asp:Parameter Name="idade" />
            <asp:Parameter Name="responsavel" />
            <asp:Parameter Name="endereco" />
            <asp:Parameter Name="bairro" />
            <asp:Parameter Name="idBeneficiario" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="nome" />
            <asp:Parameter Name="dataNascimento" />
            <asp:Parameter Name="idade" />
            <asp:Parameter Name="responsavel" />
            <asp:Parameter Name="endereco" />
            <asp:Parameter Name="bairro" />
        </InsertParameters>
    </asp:SqlDataSource>
</asp:Content>
